package com.ck.juc;

import java.util.concurrent.CountDownLatch;

/**
 *
 * 初始化线程计数器为4，只有当4个线程全部都执行完成后
 * 主线程才继续执行
 *
 */
public class CountDownLatchDemo {

    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(4);
        for(int index = 0;index < 4;index++){
            new Thread(new Runnable() {
                @Override
                public void run() {
                    System.out.println(Thread.currentThread().getName() + "\t 执行");
                    countDownLatch.countDown();
                }
            },String.valueOf(index)).start();
        }
        countDownLatch.await();
        System.out.println(Thread.currentThread().getName() + "\t 执行");
    }
}
